<<<<<<< .mine
var EWGL = EWGL || {}
=======
var EWGL = EWGL || {};
>>>>>>> .r49

(function(){
/*****************************************************************
 *
 *	The shader object
 *
 *****************************************************************/
 
	function shader(gl,shaderdescription){
		var vsshader = getcompiledshader(gl,shaderdescription.vs,"vertex"),
			fsshader = getcompiledshader(gl,shaderdescription.fs,"fragment"),
			shaderprogram = gl.createProgram(),
			i,j,
			attrresult = {},
			uniresult = {};
			
		gl.attachShader(shaderprogram, vsshader);
		gl.attachShader(shaderprogram, fsshader);
		gl.linkProgram(shaderprogram);
		
		if (!gl.getProgramParameter(shaderprogram, gl.LINK_STATUS)){
			alert("Could not initialise shaders");
		}
		this.shaderprogram = shaderprogram;
		gl.useProgram(shaderprogram);
		
		if (shaderdescription.attributes != undefined) {
			i = shaderdescription.attributes.length;
			while (i--) {
				j = shaderdescription.attributes[i];
				attrresult[j] = getshaderattributes(gl,shaderprogram,j);
			}
		}
		
		if (shaderdescription.uniforms != undefined){
			i = shaderdescription.uniforms.length;
			while (i--) {
				j = shaderdescription.uniforms[i];
				uniresult[j] = getuniformmatrices(gl,shaderprogram,j);
			}
		}
		this.name = shaderdescription.name
		this["attributes"] = attrresult;
		this["uniforms"] = uniresult;
		
		return this;
	}
	
	var types = {	"vertex" : 35633,
					"fragment" : 35632};
	
	getcompiledshader = function(gl,shaderid,type){
		var u = EWGL.util;
		
		var shaderel = document.getElementById(shaderid),
			text = shaderel ? u.getDOMNodeText(shaderid) : shaderid,
			shader = gl.createShader(types[type]);
			
		gl.shaderSource(shader, text);
		
		gl.compileShader(shader);
		if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS))
		{
			alert(gl.getShaderInfoLog(shader));
			return null;
		}
		return shader;
	}
	
	function getshaderattributes(gl,shaderProgram,attributename)
	{    
		var Attribute = gl.getAttribLocation(shaderProgram, attributename);
		gl.enableVertexAttribArray(Attribute);
		return Attribute;
	}

	function getuniformmatrices(gl,shaderProgram,uniformname)
	{
		return gl.getUniformLocation(shaderProgram, uniformname);
	}
	shader.extractUniforms = function(source){
		var reg = new RegExp("\uniform ((bool|int|uint|float|[biu]?vec[234]|mat[234]x?[234]?) ([A-Za-z0-9]*));","gi");
		var tmp;
		var returnvalue= [];
		while (tmp = reg.exec(str)){
			returnvalue.push(tmp[3]);
		};
		return returnvalue
	}
		
	
	EWGL.shader = shader
})();	